
cmake_minimum_required(VERSION 3.22)
project(cpp_test CXX C)
message(STATUS "Building project: ${PROJECT_NAME}")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

# message(STATUS "C++ compiler supports these features:")
# foreach(i ${CMAKE_CXX_COMPILE_FEATURES})
#   message(STATUS "${i}")
# endforeach()

if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
	message(STATUS "current platform: Linux ")
    add_compile_options(-O0 -g)
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
    if (MSVC)
        add_compile_options(/utf-8)
        message(STATUS "current platform: Windows Visual Studio")
    endif ()
else()
	message(STATUS "current platform: unkown")
endif()

# set(CMAKE_PREFIX_PATH libuv)
find_package(libuv REQUIRED PATHS libuv NO_DEFAULT_PATH)
if (libuv_FOUND)
    message(STATUS "Found libuv library !")
endif()

set(SOURCE_DIR source)
file(GLOB ALL_ITEMS ${SOURCE_DIR}/*)
foreach(ITEM ${ALL_ITEMS})
    if(IS_DIRECTORY ${ITEM})
        get_filename_component(EXE_NAME ${ITEM} NAME_WE)
        message(STATUS "Target: ${EXE_NAME}")
        file(GLOB_RECURSE SOURCES ${ITEM}/*.cc)
        add_executable(${EXE_NAME} ${SOURCES})
        target_link_libraries(${EXE_NAME} PUBLIC libuv::uv_a)
    endif()
endforeach()
